<?php
Globals::requireController('Admin');
Globals::requireTable('Log');
Globals::requireTable('User');

class LogController extends AdminController
{
	protected $logTable;
	protected $userTable;
	
	public function __construct($config = null)
	{
		parent::__construct($config, 'log');
		
		$this->logTable	= new LogTable($config);
		$this->userTable= new UserTable($config);
	}
	
	public function indexAction()
	{
		$params	= $this->getParams('userid,message');
		$where	= array();
		
		if ($params['userid'])
			$where['userid'] = intval($params['userid']);
		
		if ($params['message'])
			$where['message LIKE ?'] = '%'.$params['message'].'%';
		
		$count		= $this->logTable->listCount($where);
		$pageSize	= 20;
		
		$this->view->params		= $params;
		$this->view->paging		= $this->getPaging($count, $pageSize, $pageId);
		$this->view->data		= $this->logTable->listPage($where, 'time DESC', $pageSize, $pageId);
		$this->view->userTable	= $this->userTable;
		$this->view->userData	= $this->userTable->listAll(null, 'id ASC');
	}
	
	public function deleteAction()
	{
		$id = $this->getIntParam('id');
		$result = $this->logTable->delete($id);
		$this->log('删除日志'.($result ? '成功' : '失败').'(id: '.$id.')');
		$this->redirectToAction();
	}
}
